package com.carleasoft.mps.adu.business.user.controller;

import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.adu.business.user.bean.entity.MAuthorityUserVacation;
import com.carleasoft.mps.adu.business.user.bean.po.MAuthorityUserVacationPo;
import com.carleasoft.mps.adu.business.user.bean.vo.MAuthorityDeptCountVo;
import com.carleasoft.mps.adu.business.user.bean.vo.MAuthorityUserVacationVo;
import com.carleasoft.mps.adu.business.user.service.IMAuthorityUserVacationService;
import com.carleasoft.mps.core.result.R;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.util.List;

/**
 * 人员休假Controller
 * 
 * @author ruoyi
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/userVacation")
public class MAuthorityUserVacationController
{
    @Autowired
    private IMAuthorityUserVacationService mAuthorityUserVacationService;

    /**
     * 查询人员休假列表
     */
    @PostMapping("/list")
    public R list(@RequestBody MAuthorityUserVacationPo mAuthorityUserVacationPo)
    {
        Page<MAuthorityUserVacationVo> list = mAuthorityUserVacationService.selectMAuthorityUserVacationList(new Page(mAuthorityUserVacationPo.getCurrent(), mAuthorityUserVacationPo.getSize()),mAuthorityUserVacationPo);
        return R.ok(list);
    }

    /**
     * 导入人员休假
     * @param file
     * @return
     */
    @PostMapping("/importUserVacationExcel")
    public R importUserDynamicExcel(@RequestPart("file") MultipartFile file) {
        boolean isOk = mAuthorityUserVacationService.userDynamicExcel(file);
        return R.ok(isOk);
    }


    /**
     * 人员休假导出
     * @param startTime
     * @param response
     * @return
     */
    @PostMapping("/exportUserVacationExcel")
    public R<Boolean> export(HttpServletResponse response,@RequestPart("startTime") String startTime) throws ParseException {
        return R.ok(mAuthorityUserVacationService.export(response,startTime));
    }

    /**
     * 获取人员休假详细信息
     */
    @PostMapping(value = "/getById")
    public R getInfo(@RequestBody MAuthorityUserVacationPo mAuthorityUserVacationPo)
    {
        return R.ok(mAuthorityUserVacationService.selectMAuthorityUserVacationById(mAuthorityUserVacationPo.getId()));
    }

    /**
     * 新增人员休假
     */
    @PostMapping("/add")
    public R add(@RequestBody MAuthorityUserVacation mAuthorityUserVacation)
    {
        return R.ok(mAuthorityUserVacationService.insertMAuthorityUserVacation(mAuthorityUserVacation));
    }

    /**
     * 根据部门CODE分组求和轮休总数
     */
    @PostMapping("/deptCount")
    public R deptCount()
    {
        List<MAuthorityDeptCountVo> list = mAuthorityUserVacationService.selectMAuthorityDeptCountByDeptCode();
        return R.ok(list);
    }

    /**
     * 修改人员休假
     */
    @PostMapping("/update")
    public R edit(@RequestBody MAuthorityUserVacation mAuthorityUserVacation)
    {
        return R.ok(mAuthorityUserVacationService.updateMAuthorityUserVacation(mAuthorityUserVacation));
    }

    /**
     * 删除人员休假
     */
	@PostMapping("/delete")
    public R remove(@RequestBody MAuthorityUserVacation mAuthorityUserVacation)
    {
        return R.result(mAuthorityUserVacationService.deleteMAuthorityUserVacationById(mAuthorityUserVacation.getId()));
    }
}
